<template>
	<view class="page">

		<view class="page-content ">
			<u-tabs :list="list" :is-scroll="false" active-color="#F24646" :current="current" @change="change"></u-tabs>
			<view class="line"></view>
			<view class="p12 pb0" @click="toPage('/pages/user/balance/list?type=3')">
				<view class="p15 u-flex u-f-jsb" style="background: #FAEFEF;
				box-shadow: 0px 4px 12px 0px rgba(194,178,166,0.1);
				border-radius: 0px 0px 0px 0px;
				border: 1px solid rgba(242,70,70,0.2);color:#F24646">
							<span>{{typeAttr[current]}}</span>
							<span>
								<span v-if="current==0">{{xsTotal.amount}}</span>
								<span v-if="current==1">{{ywTotal.amount}}</span>
								
								元</span>
						</view>
			</view>
			<view class="p12">

				<view class=" " v-for="(item,index) in dataList" :key="index">
					<view v-if="current==0" class="bg-white mb15 p10 u-flex"
						style="box-shadow: 0px 8px 20px 0px rgba(230,219,209,0.25);">

						<image v-if="item.img && item.img!='null'" :src="item.img" style="width:200rpx;height: 200rpx;"
							mode="aspectFill"></image>
						<view class="u-f1 pl10">
							<view class="fz14 u-f-jsb u-flex">{{item.propertyName}}<span
									class="status fz12">{{item.statusDesc}}</span>
							</view>
							<view class="fz12 mt4 c9 u-line-1">{{item.detailedAddress}}</view>
							<view class="fz12 mt4 c9 u-line-1">日期 {{item.createTimeFormat}}</view>
							<view class="fz12 mt5" v-if="item.propertyValue" style="color: rgb(242, 70, 70);">线索奖励：￥{{item.propertyValue}}</view>
							<view class="u-flex fz12 mt8">
								<!-- <span class="c6">房源类别</span> -->
								<span class="color-price" style="color: #FBB03B;">{{item.categoryName}}</span>
							</view>
							<view class="u-flex fz12 u-f-jsb mt12" v-if="item.status==1 || item.status==5">
								<span class="c6"></span>
								<view class="u-flex">
									<view class="btn" @click="toEdit(item)">编辑</view>
									<view class="btn btn-del ml10" @click="toDel(index)">删除</view>
								</view>
							</view>
							<!-- <view class="u-flex fz12 mt5">
								<span class="c6">承包合约</span>
								<span class="color-price ml6">{{item.leaseStartDate}}-{{item.leaseEndDate}}</span>
							</view> -->
						</view>
					</view>
					<view v-if="current==1" @click="toInfo(item)" class="bg-white mb15 p10 u-flex"
						style="box-shadow: 0px 8px 20px 0px rgba(230,219,209,0.25);align-items: flex-start;">
						<image :src="item.mainImage" style="width:200rpx;height: 200rpx;min-width:200rpx;"
							mode="aspectFill"></image>
						<view class="u-f1 ml10">

							<view class="fz13 u-line-2">{{item.propertyName}}</view>
							<view class="u-f-jsb u-flex mt10">
								<view class="u-flex fz12 ">
									<span class="c6">累计收益</span>
									<span class="color-price ml6">{{item.salespersonIncomeAmount}}</span>
								</view>

								<view class="u-flex fz12">
									<span class="c6">月租</span>
									<span class="color-price ml6">￥{{item.rentAmount}}</span>
								</view>
							</view>


							<view class="u-flex fz12 mt5">
								<span class="c6">{{item.isRented==1?'出租中':'未出租'}}</span>
								<span class="color-price ml6" v-if="item.leaseEndDateFormat && item.isRented==1">租期至{{item.leaseEndDateFormat}}</span>
							</view>
							<view class="u-flex fz12 mt12 ">
								<span class="color-price u-f1" @click.stop="toPeople(item)">租客信息</span>
								<span class="color-price u-f1" @click.stop="toMoney(item)">收益明细</span>
							</view>

						</view>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="loadStatus"></u-loadmore>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 1,
				list: [{
					name: '我的线索',
					id: '1',
					count: 0
				}, {
					name: '我的房源',
					id: '2',
					count: 0
				}, ],
				typeAttr:['合计线索奖励','提成总收入'],
				cateList: [],
				loadStatus: 'more',
				scrollHeight: 300,
				dataList: [],
				xsTotal:{},
				ywTotal:{},
				page: 1,
			}
		},
		onLoad(e) {
			if (e.tab) {
				this.current = e.tab
			}

			this.$nextTick(() => {
				this.initData()
			})

				this.$api.xsTotal({}, (res) => {
					if (res.code == 200) {
						this.xsTotal = res.data
					}
				})
				this.$api.ywTotal({}, (res) => {
					if (res.code == 200) {
						this.ywTotal = res.data
					}
				})
				
				
				
					this.$api.getMeHousing({}, (res) => {
						if (res.code == 200) {
							this.list[0].count=res.data.total
						}
					})
					this.$api.productMy({}, (res) => {
						if (res.code == 200) {
							this.list[1].count=res.data.total
						}
					})
			this.$api.notifyGetCategoryList({}, (res) => {
				if (res.code == 200) {
					this.cateList = res.data
				}
			})
		},
		onShow() {},
		// 页面下拉到底部触发
		onReachBottom() {
			if (this.loadStatus == 'more') {
				this.getData()
			}
		},
		methods: {
			toPage(url){
				if(this.current==0){
					return
				}
				uni.navigateTo({
					url
				})
			},
			toInfo(item){
					uni.navigateTo({
						url: `/pages/product/info?id=${item.id}`
					})
			},
			toPeople(item) {
				uni.navigateTo({
					url: `/pages/house/people?id=${item.id}&houseName=${item.propertyName}`
				})
			},
			toMoney(item) {
				uni.navigateTo({
					url: `/pages/house/money?type=2&id=${item.id}&houseName=${item.propertyName}`
				})
			},
			toEdit(info) {

				this.cateList.some(item => {
					if (item.id == info.categoryId) {

						uni.navigateTo({
							url: `/pages/house/add?frontDisplayFields=${item.frontDisplayFields}&id=${item.id}&curId=${info.id}`
						})
					}
				})
			},
			change(e) {
				this.current = e
				this.initData()
			},
			initData() {
				this.page = 1
				this.dataList = []
				this.getData()
			},

			toDel(idx) {


				this.$common.modelShow('提示', '确认删除该数据吗?', () => {



					this.$api.cluemanagementDel({
						id: this.dataList[idx].id
					}, res => {
						if (res.code) {
							uni.showToast({
								title: '删除成功',
								icon: 'none'
							});
							this.dataList.splice(idx, 1)
						} else {

							uni.showToast({
								title: res.message,
								icon: 'none'
							});
						}
					})
				});

			},
			getData() {
				if (this.current == 0) {

					this.$api.getMeHousing({
						pageNo: this.page,
						pageSize: 10,
					}, res => {
						if (res.code) {
							res.data.list.some(item => {
								if (item.propertyImages) {
									this.$set(item, 'img', item.propertyImages.split(',')[0])
								}
								this.list.some(item1 => {
									if (item.status == item1.id) {
										this.$set(item, 'statusDec', item1.name)
									}

								})
							})
							let _list = res.data.list
							this.dataList = [...this.dataList, ..._list]
							// 判断所有数据是否请求完毕
							if (res.data.total > this.dataList.length) {
								this.page++
								this.loadStatus = 'more'
							} else {
								this.loadStatus = 'noMore'
							}
						}
					})
				} else {

					this.$api.productMy({
						pageNo: this.page,
						pageSize: 10,
					}, res => {
						if (res.code) {
							res.data.list.some(item => {
								if (item.propertyImages) {
									this.$set(item, 'img', item.propertyImages.split(',')[0])
								}
								this.list.some(item1 => {
									if (item.status == item1.id) {
										this.$set(item, 'statusDec', item1.name)
									}

								})
							})
							let _list = res.data.list
							this.dataList = [...this.dataList, ..._list]
							// 判断所有数据是否请求完毕
							if (res.data.total > this.dataList.length) {
								this.page++
								this.loadStatus = 'more'
							} else {
								this.loadStatus = 'noMore'
							}
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn {
		padding: 0 30rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		background: rgba(242, 70, 70, 0.1);
		color: #F24646;
		border-radius: 40px;

		&.btn-del {
			background: #f5f5f5;
			color: #999;
		}
	}

	.line {
		width: 750rpx;
		height: 4rpx;
		position: relative;
		top: -4rpx;
		background: #F6F9F9;
		border-radius: 0px 0px 0px 0px;
	}

	.status1 {
		color: #E54440;
	}

	.status2 {
		color: #39959B;
	}

	.status3 {
		color: #333;
	}
</style>